2020-2021 Sunseeker Telemetry and Lighting System
pmm_ex3_lowCurrentConsumption.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
70 //******************************************************************************
71 
72 #include "driverlib.h"
73 
74 #define DUTY_CYCLE1 32
75 #define TIMER_PERIOD 40
76 
77 void main (void)
78 {
79  //Stop WDT
80  WDT_A_hold(WDT_A_BASE);
81 
82  //Set DCO FLL reference = REFO
83  UCS_initClockSignal(UCS_FLLREF,
84  UCS_REFOCLK_SELECT,
85  UCS_CLOCK_DIVIDER_1
86  );
87 
88  //Set ACLK = REFO
89  UCS_initClockSignal(UCS_ACLK,
90  UCS_REFOCLK_SELECT,
91  UCS_CLOCK_DIVIDER_1
92  );
93 
94  //~ 32*32768 = 1048576
95  UCS_initFLLSettle(1048,
96  32
97  );
98 
99  //Monitor low side is turned off
100  PMM_disableSvmL();
101 
102  //Monitor high side is turned off
103  PMM_disableSvmH();
104 
105  //SVS Low side is turned on
106  PMM_enableSvsL();
107 
108  //Reset (POR) on SVS trigger
109  PMM_enableSvsLReset();
110 
111  //Slow wake up from LPMs,// SVSL turns off in LPM3,power-save
112  PMM_disableSvsLInLPMSlowWake();
113 
114  //SVSL turns off in LPM3,power-save
115  PMM_enableSvsH();
116 
117  //SVS High side is turned on
118  PMM_enableSvsHReset();
119 
120  //Normal Perf mode,
121  PMM_disableSvsHInLPMNormPerf();
122  //Wait until high side, low side settled
123  while ( 0 == PMM_getInterruptStatus(
124  PMM_SVSMLDLYIFG + PMM_SVSMHDLYIFG )
125  ) ;
126 
127  //SVSH turns off in LPM3,power-save
128  PMM_clearPMMIFGS();
129 
130  //Clear P1.0 LED off
132  GPIO_PORT_P1,
133  GPIO_PIN0
134  );
135 
136  //Set P1.0 to output direction
137  GPIO_setAsOutputPin(
138  GPIO_PORT_P1,
139  GPIO_PIN0
140  );
141 
142  //P1.5 TA0.4 output 50% duty cycle
143  //Set P1.0 to output direction
144  GPIO_setAsPeripheralModuleFunctionOutputPin(
145  GPIO_PORT_P1,
146  GPIO_PIN5
147  );
148 
149  //Start timer in upMode sourced by ACLK
150  Timer_A_clearTimerInterrupt(TIMER_A0_BASE);
151 
152  Timer_A_initUpModeParam initUpParam = {0};
153  initUpParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
154  initUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
155  initUpParam.timerPeriod = TIMER_PERIOD;
156  initUpParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE;
157  initUpParam.captureCompareInterruptEnable_CCR0_CCIE =
158  TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;
159  initUpParam.timerClear = TIMER_A_DO_CLEAR;
160  initUpParam.startTimer = true;
161  Timer_A_initUpMode(TIMER_A0_BASE, &initUpParam);
162 
163  //Generate PWM using capture
164  Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE,
165  TIMER_A_CAPTURECOMPARE_REGISTER_4
166  );
167 
168  Timer_A_initCompareModeParam initCompParam = {0};
169  initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_4;
170  initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
171  initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;
172  initCompParam.compareValue = DUTY_CYCLE1;
173  Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam);
174 
175  //Enter LPM3, enable interrupts
176  __bis_SR_register(LPM3_bits + GIE);
177  //For debugger
178  __no_operation();
179 }
180 
181 //******************************************************************************
182 //
183 //This is the Timer0_A5 interrupt vector service routine.
184 //
185 //******************************************************************************
186 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
187 #pragma vector=TIMER0_A1_VECTOR
188 __interrupt
189 #elif defined(__GNUC__)
190 __attribute__((interrupt(TIMER0_A1_VECTOR)))
191 #endif
192 void TIMER0_A1_ISR (void)
193 {
194  switch (__even_in_range(TA0IV,14)){
195  case 0: break; //No interrupt
196  case 2: break; //CCR1 not used
197  case 4: break; //CCR2 not used
198  case 6: break; //reserved
199  case 8: break; //reserved
200  case 10: break; //reserved
201  case 12: break; //reserved
202  case 14: //overflow
203  //Toggle P1.0
204  GPIO_toggleOutputOnPin(
205  GPIO_PORT_P1,
206  GPIO_PIN0
207  );
208  break;
209  default: break;
210  }
211 }
212 
__no_operation()
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
void main(void)
#define DUTY_CYCLE1
#define TIMER_PERIOD
void TIMER0_A1_ISR(void)